package com.michaelwolf.mytool.ruwlsr;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class JobInfo {
	
	private File wcfFile;
	
	private File stringFile;
	
	private File typeFile;
	
	private String moduleName;
	
	private StringBuffer usingStrContentBuffer = new StringBuffer();
	
	private List<String> strList = new ArrayList<String>();
	
	public JobInfo(String dir, String moduleName){
		this.moduleName = moduleName;
		
		wcfFile = new File(dir+"\\wcf.xml");
		typeFile = new File(dir+"\\types.xml");
		stringFile = new File(dir + "\\strings.properties");
		
		try {
			loadWCFFileContent();
			loadTypeFileContent();
			loadStringFileContectForStrID();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	private void loadTypeFileContent() throws IOException {
		InputStream is = new FileInputStream(typeFile);
		BufferedReader reader = new BufferedReader(new InputStreamReader(is));
		
		try{
			String line = reader.readLine();
			while(line!=null){
				usingStrContentBuffer.append(line);
				line = reader.readLine();
			}
		}catch(IOException ex){
			ex.printStackTrace();
		}finally{
			reader.close();
		}
		
	}

	public File getWcfFile() {
		return wcfFile;
	}

	public void setWcfFile(File wcfFile) {
		this.wcfFile = wcfFile;
	}

	public File getStringFile() {
		return stringFile;
	}

	public void setStringFile(File stringFile) {
		this.stringFile = stringFile;
	}

	public String getModuleName() {
		return moduleName;
	}

	public void setModuleName(String moduleName) {
		this.moduleName = moduleName;
	}
	
	public void loadWCFFileContent() throws IOException{
		InputStream is = new FileInputStream(wcfFile);
		BufferedReader reader = new BufferedReader(new InputStreamReader(is));
		
		try{
			String line = reader.readLine();
			while(line!=null){
				usingStrContentBuffer.append(line);
				line = reader.readLine();
			}
		}catch(IOException ex){
			ex.printStackTrace();
		}finally{
			reader.close();
		}
	}
	
	public void loadStringFileContectForStrID() throws IOException{
		InputStream is = new FileInputStream(stringFile);
		BufferedReader reader = new BufferedReader(new InputStreamReader(is));
		
		try{
			String line = reader.readLine();
			while(line!=null){
				strList.add(line);
				line = reader.readLine();
			}
		}catch(IOException ex){
			ex.printStackTrace();
		}finally{
			reader.close();
		}
	}
	
	public StringBuffer getUsingStrContent(){
		return usingStrContentBuffer;
	}
	
	public List<String> getStringList(){
		return strList;
	}
	
	public String toString(){
		return "moduleName="+ moduleName + " path="+ wcfFile.getPath();
	}

	
}
